Skip to content

Report clean analytics paths and redirect /sitemap.xml - #35

Merged
joancomadran merged 2 commits into
mainfrom
cursor/analytics-pathname-sitemap-3386
Nov 13, 2026
Merged

joancomadran merged 2 commits into
mainfrom
cursor/analytics-pathname-sitemap-3386

Conversation

@joancomadran

Copy link
Copy Markdown
Owner

Why

Vercel Web Analytics on the Astro pages was recording file-build pathnames (/index.html, /es.html, /blog.html, /404.html) because @vercel/analytics/astro copies Astro.url.pathname into data-pathname. With build.format: 'file' that pathname includes .html, even though cleanUrls serves /, /es, and /blog. The 404 document is always /404.html, so broken URLs never showed up. /sitemap.xml also 404s while robots.txt points at /sitemap-index.xml.

What changed

  • A classic inline script rewrites data-pathname before the deferred analytics module defines <vercel-analytics> and sends its one pageview. Static pages drop /index.html and .html. The 404 page reports location.pathname (including a miss that itself ends in .html).
  • The stock @vercel/analytics/astro component still performs the only inject() / pageview(). disableAutoTrack, framework: 'astro', and window.webAnalyticsBeforeSend are unchanged, so custom events and the editor's React analytics are left alone.
  • vercel.json permanently redirects /sitemap.xml to /sitemap-index.xml (Vercel permanent: true, HTTP 308). /sitemap-index.xml and /sitemap-0.xml are not redirected.

Verification

  • npm test
  • npm run lint
  • npm run build (astro check and the static build)
  • npx playwright test (22 passed on Chromium and mobile Chromium)

Built HTML still has one <vercel-analytics> element. Playwright queued a single pageview of /, /es, and /blog/edit-raw-photos-in-browser (route /blog/[slug]), and /no-such-page on the 404. /editor has no Astro analytics element. dist contains sitemap-index.xml and sitemap-0.xml, and no sitemap.xml.

Open in Web Open in Cursor 

cursoragent and others added 2 commits November 13, 2026 04:43
Astro's file build format was sending /index.html, /es.html, and /404.html.
Rewrite data-pathname before the analytics element records its single pageview,
and use the requested URL on the 404 document.

Co-authored-by: Joan Comadran <joancomadran@users.noreply.github.com>
robots.txt already points at the index. A permanent Vercel redirect covers
the conventional sitemap path without touching sitemap-index.xml or sitemap-0.xml.

Co-authored-by: Joan Comadran <joancomadran@users.noreply.github.com>
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lightframes Ready Ready Preview Nov 13, 2026 4:43am UTC

Request Review

@joancomadran
joancomadran merged commit d3d7404 into main Nov 13, 2026
5 checks passed
@joancomadran
joancomadran deleted the cursor/analytics-pathname-sitemap-3386 branch November 13, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants